<template>
  <views class="invoice_manager">
    <viewTitle :title="'企业查询'" :border="false"></viewTitle>
    <!-- 搜索栏 -->
    <div class="search flex flexC">
      <!-- 商户编号-客户名称-开票时间 -->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="search_input flex flexR center">
          <div class="bank_statement flex flexR center">
            <el-form-item label="客户编号:">
              <el-input v-model="form.enterprise_sn" placeholder="请输入客户编号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="bank_statement flex flexR center">
            <el-form-item label="客户名称:">
              <el-input v-model="form.enterprise_name" placeholder="请输入客户名称" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <el-form-item>
            <div class="flex flexR pay_btn_list">
              <el-button type="primary" @click="getData" icon="el-icon-search">查看</el-button>
              <el-button @click="reset()" icon="el-icon-refresh">重置</el-button>
              <el-button type="danger" @click="exportExcel" icon="el-icon-download">导出列表</el-button>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <!-- 表格 -->
    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column fixed type="index" label="序号" width="100"></el-table-column>
        <el-table-column fixed prop="enterprise_sn" label="客户编号" width="200"></el-table-column>
        <el-table-column prop="enterprise_name" label="客户名称" width="150"></el-table-column>
        <el-table-column prop="total_charge" label="累计充值金额" width="120"></el-table-column>
        <el-table-column prop="invoice_money" label="已申请开票金额" width="300"></el-table-column>
        <el-table-column prop="noinvoice_money" label="可开票金额" width="auto"></el-table-column>
        <el-table-column prop="zip" label="操作" fixed="right" width="200">
          <template slot-scope="scope">
            <div class="table_operation">
              <el-button type="primary" @click="toDetailList(scope)">详情</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="flex flexR paging">
      <el-pagination
        style="background:#fff; padding:10px 0"
        background
        layout="total, sizes,prev, pager, next, jumper"
        @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
        @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pagination.page_size"
        :total="pagination.total_count"
        :current-page="pagination.current_page"
        :page-count="pagination.page_count"
      ></el-pagination>
    </div>
  </views>
</template>




<script>
export default {
  data() {
    return {
      tableData: [],
      pagination: {
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      download_url: "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      form: {
        enterprise_sn: "", //  客户编号
        enterprise_name: "" //  客户名称
      }
    };
  },
  methods: {
    changeTime() {
      if (this.make_time) {
        this.start_time = this.make_time[0]/1000
        this.end_time = this.make_time[1]/1000
      } else {
        this.start_time = "";
        this.end_time = "";
      }
    },
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //     点击单行
    clickRow(row, column, event) {
      console.log(row, column, event);
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    //    去开票记录列表
    toDetailList(scope) {
      this.$toRoutePath({
        path: "/invoice_manager/invoice_manager_log",
        edit: true,
        query: {enterprise_id:scope.row.enterprise_id}
      });
    },
    //   查询
    getData() {
      this.form.pagination = this.pagination;
      let { code, msg, data } = this.$api.sendSync(
        this.$mapapi.fenterpriseInvoice,
        this.form
      );
      if (code != 200 && code != 501) {
        this.$message.error(msg);
        return;
      }
      this.tableData = data.list;
      this.pagination = data.pagination;
      this.download_url = data.download_url;
    },
    //   重置
    reset() {
      this.form.enterprise_sn = ""; //  客户编号
      this.form.enterprise_name = ""; //  客户名称
      this.getData();
    },
    //   导出
    exportExcel() {
      this.$import_excal(this.download_url || "");
    }
  },
  mounted() {
    this.getData();
  },
  created() {}
};
</script>




<style lang="less"  :scope="true"  src="@/style/invoice/invoice_manager.less" >
</style>